# coding=utf-8
import configparser
# pip install ConfigPars


# red_ini = configparser.ConfigParser()
# red_ini.read('D:/test/Appium2021/config/LocalElement.ini')#绝对路径
# red_ini.read('../config/LocalElement.ini') #相对路径
# print(red_ini.get('login_element','login_button'))

class ReadIni:
    def __init__(self,file_path=None):
        if file_path == None:
            self.file_path = '../config/LocalElement.ini'
        else:
            self.file_path = file_path
        self.date = self.read_ini()
    def read_ini(self):
        red_ini = configparser.ConfigParser()
        red_ini.read(self.file_path,encoding='UTF-8')
        return red_ini

    # 通过key获取对应得value
    def get_value(self, key, section=None):
        if section == None:
            section = 'login_element'
        try:
            value =self.date.get(section,key)
        except:
            value =None
            print(key+"元素不存在")
        return value



# if __name__ == '__main__':
#    read_ini = ReadIni()
#    print(read_ini.get_value("login_button","login_element"))
